<?php
/*  Code Module for Websitebaker
    Copyright 2011 Ryan Djurovich and Norbert Heimsath (Heimsath.org)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require('../../config.php');

// suppress to print the header, so no new FTAN will be set
$admin_header = false;

// Tells script to update when this page was last updated
$update_when_modified = true;

// Include WB admin wrapper script
require(WB_PATH.'/modules/admin.php');

if (!$admin->checkFTAN()) {
	$admin->print_header();
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
}
$admin->print_header();

// Update the mod_wysiwygs table with the contents
if(isset($_POST['content'])) {
	/*$tags = array('<?php', '?>' , '<?');*/
	//$content = $admin->add_slashes(str_replace($tags, '', $_POST['content']));
	$content = $admin->add_slashes($_POST['content']);
	$query = "UPDATE ".TABLE_PREFIX."mod_code SET content = '$content' WHERE section_id = '$section_id'";
	$database->query($query);	
}

$codelocation= WB_PATH."/temp/modules/code/section_".$section_id.".php.inc";

if (file_exists($codelocation)){
	if (!unlink ($codelocation)) {
		$admin->print_error("Cannot delete accesfile: $codelocation", $js_back);
	}
}
// Check if there is a database error, otherwise say successful
if($database->is_error()) {
	$admin->print_error($database->get_error(), $js_back);
} else {
	$admin->print_success($MESSAGE['PAGES_SAVED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
}

// Print admin footer
$admin->print_footer();

?>